package Tree;

public class _701_InsertintoaBinarySearchTree {
    public TreeNode insertIntoBST(TreeNode root, int val) {
        if(root==null) return null;
        int rval = root.val;
        if (rval > val) {
            if (root.left != null) {
                insertIntoBST(root.left, val);
            } else {
                TreeNode lnode = new TreeNode(val);
                root.left = lnode;
            }
        } else {
            if (root.right != null) {
                insertIntoBST(root.right, val);
            } else {
                TreeNode rnode = new TreeNode(val);
                root.right = rnode;
            }
        }
        return root;
    }

}
